var Feedback = {
	send: function() {
		question = $("#feedback").val();
		if (question == "") {
			(CurrentUser.category==30?$alert("问题内容为空"):$alertEn("The content is empty"));
			return;
		}
		var time = new Date().pattern("yyyy-MM-dd");
		$ajax({
			url: "/feedback/upsert",
			data: {
				from: CurrentUser._id,
				question: question
			},
			success: function(res) {
			  if(CurrentUser.category==30){ 
				$("#feedback").blur();
				PCall("feedback_list", "CCall('Feedback.listInit();')");
				$alert("发送成功,感谢您的配合！");
				WinClose();
		      }else{
				$("#feedback").blur();
                PCall("feedback_list", "CCall('Feedback.listInit();')");
                $alertEn("Successfully Sent,Thank you for your cooperation!");
                WinClose();
				}
			}
		});
	},
	listInit: function() {
		$ajax({
			url: "/feedback/list",
			data: {
				from: CurrentUser._id,
			},
			success: function(res) {
				var length = res.result.count;
				var fk=CurrentUser.category==30?"您尚未反馈任何问题，快去提问吧!":"You haven’t submit ted your feedback yet.";
				if (length == 0)
					return $("#ctn").html(" <div id='nofeed' class='ub t_blu umt_6 ufb tx-c'></div>"+'<div class="tx-c umt_6">'+fk+'</div>');
				var result = res.result.results;
				var html = "";
				for (var i = 0; i < length; i++) {
				    if(CurrentUser.category==30){
				      html += '<div class="ubb b-gra up_base">' +
                        '   <div class="ub ub-ver">' +
                        '       <div class="c_base upb_p5">'+CurrentUser.category==30?"请问":"Question"+'</div>' +
                        '       <div class="ulev-1 upb_p5">　　' + result[i].question.replace(/\n/g, "</br>") + '</div>' +
                        '       <div class="ub ub-pe upb_p5 ulev-2 t-gra">' + new Date(result[i].create).pattern("yyyy-MM-dd HH:mm") + '</div>' +
                        '    </div>'
                    if (result[i].answer != undefined) {
                        html += '    <div class="ub ub-ver">' +
                                '       <div class="t-org upb_p5">+CurrentUser.category==30?"回复":"Reply"+</div>' +
                                '       <div class="ulev-1 upb_p5">　　' + result[i].answer.replace(/\n/g, "</br>") + '</div>' +
                                '       <div class="ub ub-pe upb_p5 ulev-2 t-gra">' + new Date(result[i].aDate).pattern("yyyy-MM-dd HH:mm") + '</div>' +
                                '   </div>'
                    }
                    html += '</div> ';  
				    }else{
				        html += '<div class="ubb b-gra up_base">' +
                        '   <div class="ub ub-ver">' +
                        '       <div class="c_base upb_p5">Ask：</div>' +
                        '       <div class="ulev-1 upb_p5">　　' + result[i].question.replace(/\n/g, "</br>") + '</div>' +
                        '       <div class="ub ub-pe upb_p5 ulev-2 t-gra">' + new Date(result[i].create).pattern("yyyy-MM-dd HH:mm") + '</div>' +
                        '    </div>'
                    if (result[i].answer != undefined) {
                        html += '    <div class="ub ub-ver">' +
                                '       <div class="t-org upb_p5">Reply：</div>' +
                                '       <div class="ulev-1 upb_p5">　　' + result[i].answer.replace(/\n/g, "</br>") + '</div>' +
                                '       <div class="ub ub-pe upb_p5 ulev-2 t-gra">' + new Date(result[i].aDate).pattern("yyyy-MM-dd HH:mm") + '</div>' +
                                '   </div>'
                    }
                    html += '</div> ';
				    }
				}
				$("#ctn").html(html);
			}
		});
	}
}